package com.bulls.demo.hrmsdemo.utils;

import java.beans.BeanInfo;
import java.beans.IntrospectionException;
import java.beans.Introspector;
import java.beans.PropertyDescriptor;
import java.lang.reflect.Field;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;

public class Utilities {
	
	public static boolean isNull(String value){
		boolean boo = true;
		if(value!=null && value.length()>0){
			boo = false;
		}
		return boo;
	}
	
	public static Date convertStringtoDate(String strDate){
		SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy");
		Date date = null;
		try {
			date = sdf.parse(strDate);
		} catch (ParseException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return date;
	}
	
	public static String getResponseString(ArrayList response){
		StringBuilder result  = new StringBuilder();
		result.append("<table border='1' width='100%'> ");
		//result.append("<tr width='100%' onclick='setValue(\"hello\")'><td>hello</td></tr>");
		for(int i=0;i<response.size();i++){
			String trStr= "<tr width='100%'";
			StringBuilder tdStr = new StringBuilder();
			//result.append("<tr width='100%'>");
			HashMap<String,Object> responseRow = (HashMap<String, Object>) response.get(i);
			Set<Map.Entry<String,Object>> responseSet = responseRow.entrySet();
			String setValueString = "";
			for(Map.Entry<String,Object> entry:responseSet){
				if(setValueString.length()>0){
					setValueString += ","+entry.getValue();
				}else{
					setValueString += entry.getValue();
				}
				tdStr.append("<td>"+entry.getValue()+"</td>");
			}
			trStr += "onclick='setValue(\""+setValueString+"\")'>";
			result.append(trStr+tdStr);
			result.append("</tr>");
		}
		result.append("</table>");
		System.out.println(result.toString());
		return result.toString();
	}

}
